package com.st.configs;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    @Value("${swagger.name}")
    private String name;
    @Value("${swagger.email}")
    private String email;
    @Value("${swagger.url}")
    private String url;
    @Value("${swagger.title}")
    private String title;
    @Value("${swagger.description}")
    private String description;
    @Value("${swagger.version}")
    private String version;



    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI().info(initInfo());
    }

    public Info initInfo(){
        //定义作者信息对象
        Contact contact = new Contact()
                .name(name)
                .email(email)
                .url(url);

        return new Info()
                .title(title)
                .contact(contact)
                .version(version)
                .description(description)
                .license(new License().name("Apache 2.0"));
        }
}
